package com.xy.wsl.api.controller.User;

import com.xy.wsl.api.authorize.Authorize;
import com.xy.wsl.api.response.ResponseResult;
import com.xy.wsl.api.sql.entity.User.User;
import com.xy.wsl.api.sql.services.User.UserService;
import com.xy.wsl.api.utils.SecretUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RequestMapping("/sign")
@Slf4j
@RestController
@ResponseResult
public class SignController {

    @Autowired
    UserService service;

    @PostMapping("user")
    public Object signUser(@RequestBody User user) {

        user.setUid(UUID.randomUUID().toString().replaceAll("-",""));
        String pwd = user.getPassword();
        user.setPassword(SecretUtil.md5(pwd));
        int result = service.insert(user);

        return  result;
    }
}
